//
//  UIViewController+Present.m
//  DynamicIconDemo
//
//  Created by BaizYi on 2019/1/16.
//  Copyright © 2019 BaiziYI. All rights reserved.
//

#import "UIViewController+Present.h"
#import <objc/runtime.h>


@implementation UIViewController (Present)


+(void)load{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Method presentM = class_getInstanceMethod(self.class, @selector(presentViewController:animated:completion:));
        Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(yjy_presentViewController:animated:completion:));
        method_exchangeImplementations(presentM, presentSwizzlingM);
    });
}

-(void)yjy_presentViewController:(UIViewController *)viewController animated:(BOOL)flag completion:(void(^)(void))completion{
    if ([viewController isKindOfClass:[UIAlertController class]]) {
        
        
        NSLog(@"title : %@",((UIAlertController *)viewController).title);
        NSLog(@"message : %@",((UIAlertController *)viewController).message);
        
        UIAlertController *alertVC = (UIAlertController *)viewController;
        
        if (alertVC.title == nil && alertVC.message == nil) {
            return;
        }else{
            [self yjy_presentViewController:viewController animated:flag completion:completion];
            return;
        }
    }
    [self yjy_presentViewController:viewController animated:flag completion:completion];
}
@end
